﻿using System.Text;

namespace SmartBoard.Core.Networking
{
    public partial class SocketClientSync
    {
        private class SocketClientSyncSocketService : BaseSocketService
        {
            #region Fields

            private readonly SocketClientSync _socketClient;
            #endregion

            #region Constructor

            public SocketClientSyncSocketService(SocketClientSync client)
            {
                _socketClient = client;
            }
            #endregion

            #region Methods Overrides

            public override void OnConnected(ConnectionEventArgs e)
            {
                _socketClient._socketConnection = e.Connection;
                _socketClient._socketConnection.BeginReceive();
                _socketClient._connectEvent.Set();
            }

            public override void OnException(ExceptionEventArgs e)
            {
                _socketClient.LastException = e.Exception;
                _socketClient._exceptionEvent.Set();
            }

            public override void OnSent(MessageEventArgs e)
            {
                _socketClient._sentEvent.Set();
            }

            public override void OnReceived(MessageEventArgs e)
            {
                //_socketClient.Enqueue(Encoding.GetEncoding(1252).GetString(e.Buffer));
                _socketClient.Enqueue(e.Buffer);
                _socketClient._socketConnection.BeginReceive();
            }

            public override void OnDisconnected(ConnectionEventArgs e)
            {
                _socketClient._disconnectEvent.Set();
            }
            #endregion
        }
    }
}